﻿using System.ComponentModel;

namespace DeltaGroup.WheelOfJeopardy.UI.ViewModel
{
    public class WagerModel : BaseViewModel, IDataErrorInfo
    {
        #region Fields

        private int _wager;
        private int _maxScore;

        #endregion Fields

        #region Constructors

        /// <summary>
        ///     Initializes a new instance of the <see cref = "WagerModel" /> class.
        /// </summary>
        public WagerModel()
        {
            Wager = 1;
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        ///     Gets or sets the category.
        /// </summary>
        /// <value>The category.</value>
        public string Category { get; set; }

        /// <summary>
        ///     Gets a value indicating whether this instance is valid.
        /// </summary>
        /// <value><c>true</c> if this instance is valid; otherwise, <c>false</c>.</value>
        public bool IsValid
        {
            get { return this["Wager"] == null; }
        }

        /// <summary>
        ///     Gets or sets the max score.
        /// </summary>
        /// <value>The max score.</value>
        public int MaxScore
        {
            get { return _maxScore; }
            set
            {
                _maxScore = value;
                Wager = value;
            }
        }

        /// <summary>
        ///     Gets or sets the wager.
        /// </summary>
        /// <value>The wager.</value>
        public int Wager
        {
            get { return _wager; }
            set
            {
                _wager = value;
                FirePropertyChanged("Wager");
            }
        }

        /// <summary>
        ///     Gets an error message indicating what is wrong with this object.
        /// </summary>
        /// <value></value>
        /// <returns>An error message indicating what is wrong with this object. The default is an empty string ("").</returns>
        public string Error { get; set; }

        #endregion Properties

        #region Indexers

        /// <summary>
        ///     Gets the <see cref = "System.String" /> with the specified column name.
        /// </summary>
        /// <value></value>
        public string this[string columnName]
        {
            get
            {
                if (columnName == "Wager")
                {
                    if (Wager%100 != 0 || Wager <= 100 || Wager > MaxScore)
                        return string.Format("Wager must be between 100 and {0} and in increments of 100", MaxScore);
                }
                return null;
            }
        }

        #endregion Indexers
    }
}